<?php
namespace app\pay\controller\juyin;

use think\Controller;
use pay\juyin\Config;
use pay\juyin\PayRequest;

class Base extends Controller
{
    /**
 * [聚银]支付接口中转
 * ================================================================
 * order 银联快捷入口，方法中转
 * ================================================================
 */
    var $payRequest;
    var $cfg;
    
    public function request(){
        $this->payRequest = new PayRequest();  
        $this->cfg = new Config();
    }
    
    // 畅远规则验证签名
    public function verifySign($data, $isDaifu) {
        $signVal = model('PayBis')->createSign($data, $isDaifu);

        if($signVal === $data['signature']) {
            return json_encode(true, true);
        } else {
            return json_encode('签名错误', true);
        }
    }
    
    /*
     * 1.根据聚银的规则生成签名
     * 2.将签名加入请求字段中
     * 3.发起POST请求
     * 4.数据返回
     */
    public function requestData($data, $method, $isDaifu) {
        // 1.根据聚银的规则生成签名
        $signVal = $this->payRequest->createJuyinSign($data, $isDaifu);
        // 2.将签名加入请求字段中
        $data['signature'] = $signVal;
        $jsonData = json_encode($data, true);
        // 3.发起POST请求
        $ret = $this->payRequest->Request($method, $jsonData);
        // 4.数据返回
        return $ret;
    }
    
    
}

